package day03.`match`

/**
  * 匹配数组、元组、集合
  */
object MatchList {
  def main(args: Array[String]): Unit = {
    // 匹配数组
    val arr = Array(4, 2, 5, 7)

    arr match {
      case Array(4, a, b, c) => println(s"arr case:$a,$b,$c")
      case Array(_, a, b) => println(s"arr case:$a,$b")
      case _ => println("Not Matched Array")
    }

    //匹配元组
    val tup = (2, 3, 4)

    tup match {
      case (2, a, b) => println(s"tup case:$a,$b")
      case (_, a, b) => println(s"tup case:$a,$b")
      case _ => println("Not match Yuan zu")
    }

    //匹配集合
    val list1 = List(0, 1, 2, 3)
    list1 match {
      case List(1, a, b, c) => println("case1:0")
      case a :: b :: c :: d :: Nil => println(s"case2:$a,$b,$c,$d")
      case 0 :: a => println(s"case3:$a")
      case _ => println("Not Matched")
    }
  }
}
